package ru.dadle8.service.impl.callback.training;

import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import ru.dadle8.model.bot.type.CallbackAction;
import ru.dadle8.service.impl.callback.AbstractCallbackService;

@Service
public class EndCallbackServiceImpl extends AbstractCallbackService {

    @Override
    public int getAction() {
        return CallbackAction.END.getAction();
    }

    @Override
    public void processUpdate(Update update) throws TelegramApiException {
        // return to start action
        getStorage().clearState(getChatId());

        // avoid 'loading...'
        getBot().execute(getMessageHelper().sendAnswerCallbackQuery(getCallbackQuery()));
        // delete current menu message
        getBot().execute(getMessageHelper().sendDeleteMessage(getChatId(), getMessageId()));

        getBot().execute(getMessageHelper().sendMessage(getChatId(), "Закончили"));
    }
}
